home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 139 / Exame Informatica 139.iso / Revista / Flash / Uniform Server / diskw / home / admin / www / phpMyAdmin / queryframe.php < prev    next >
Encoding:
PHP Script  |  2005-10-20  |  18.2 KB  |  453 lines

  1. <?php
  2. /* $Id: queryframe.php,v 2.30.2.1 2005/10/21 01:27:32 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Gets the variables sent to this script, retains the db name that may have
  7.  * been defined as startup option and include a core library
  8.  */
  9. require_once('./libraries/grab_globals.lib.php');
  10. if (!empty($db)) {
  11.     $db_start = $db;
  12. }
  13.  
  14.  
  15. /**
  16.  * Gets a core script and starts output buffering work
  17.  */
  18. require_once('./libraries/common.lib.php');
  19. require_once('./libraries/bookmark.lib.php');
  20. require_once('./libraries/ob.lib.php');
  21. if ($cfg['OBGzip']) {
  22.     $ob_mode = PMA_outBufferModeGet();
  23.     if ($ob_mode) {
  24.         PMA_outBufferPre($ob_mode);
  25.     }
  26. }
  27. // security fix:
  28. if (isset($hash)) {
  29.    $hash = PMA_sanitize($hash);
  30. }
  31.  
  32. // garvin: For re-usability, moved http-headers
  33. // to a seperate file. It can now be included by header.inc.php,
  34. // queryframe.php, querywindow.php.
  35.  
  36. require_once('./libraries/header_http.inc.php');
  37.  
  38. /**
  39.  * Displays the frame
  40.  */
  41. // Gets the font sizes to use
  42. PMA_setFontSizes();
  43.  
  44. /**
  45.  * Relations
  46.  */
  47. require_once('./libraries/relation.lib.php');
  48. $cfgRelation = PMA_getRelationsParam();
  49. echo "<?xml version=\"1.0\" encoding=\"" . $GLOBALS['charset'] . "\"?".">"; // remove vertical scroll bar bug in ie
  50. ?>
  51. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  52.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  53. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>">
  54.  
  55. <head>
  56. <title>phpMyAdmin</title>
  57. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
  58. <base<?php if (!empty($cfg['PmaAbsoluteUri'])) echo ' href="' . $cfg['PmaAbsoluteUri'] . '"'; ?> />
  59. <link rel="stylesheet" type="text/css" href="./css/phpmyadmin.css.php?<?php echo PMA_generate_common_url(); ?>&js_frame=left&num_dbs=0" />
  60. <?php
  61. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
  62. ?>
  63. <script type="text/javascript" language="javascript">
  64. <!--
  65. var querywindow = '';
  66.  
  67. function open_querywindow(url) {
  68.  
  69.     if (!querywindow.closed && querywindow.location) {
  70.         querywindow.focus();
  71.     } else {
  72.         querywindow=window.open(url + '&db=' + document.queryframeform.db.value + '&table=' + document.queryframeform.table.value, '','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=yes,width=<?php echo $cfg['QueryWindowWidth']; ?>,height=<?php echo $cfg['QueryWindowHeight']; ?>');
  73.     }
  74.  
  75.     if (!querywindow.opener) {
  76.         querywindow.opener = blank;
  77.     }
  78.  
  79.     if (window.focus) {
  80.         querywindow.focus();
  81.     }
  82.  
  83.     return false;
  84. }
  85.  
  86. /**
  87.   * function resizeRowsLeft()
  88.   * added 2004-07-20 by Michael Keck <mail@michaelkeck.de>
  89.   *                  - this function checks the complete frameset of
  90.   *                    index.php (parent.frames)
  91.   *                  - gets the offsetHeight of qfcontainer
  92.   *                  - sets a new frameset.rows - definition for the
  93.   *                    frameset 'leftFrameset' in 'index.php' dynamic.
  94.   * this script was tested on
  95.   *   IE 6, Opera 7.53, Netsacpe 7.1 and Firefox 0.9
  96.   *   and should work on all other DOM-Browsers and old IE-Browsers.
  97.   *   It will never work on Netscape smaller Version 6 and IE smaller Version 4.
  98.   * Please give me feedback if any browser doesn't work with this script
  99.   *   mailto:mail@michaelkeck.de?subject=resizeFrames - Browser: [the browser]
  100. **/
  101.  
  102. function resizeRowsLeft() {
  103.     if (document.getElementById('qfcontainer')) { // dom browsers
  104.         // get the height of the div-element 'qfcontainer'
  105.         // we must add 10 (px) for framespacing
  106.         newHeight = document.getElementById('qfcontainer').offsetHeight+10;
  107.         // check if the frameset exists
  108.         // please see index.php and check the frameset-definitions
  109.         if (parent.document.getElementById('mainFrameset') && parent.document.getElementById('leftFrameset')) {
  110.             parent.document.getElementById('leftFrameset').rows=newHeight+',*';
  111.         }
  112.     } else {
  113.         if (document.all) { // older ie-browsers
  114.             // get the height of the div-element 'qfcontainer'
  115.             // we must add 10 (px) for framespacing
  116.             newHeight=document.all('qfcontainer').offsetHeight+10;
  117.             // check if the frameset exists
  118.             // please see index.php and check the frameset-definitions
  119.             if (parent.leftFrameset) {
  120.                 parent.leftFrameset.rows=newHeight+',*';
  121.             }
  122.         }
  123.     }
  124. }
  125.  
  126. //-->
  127. </script>
  128. <?php
  129.     // setup the onload handler for resizing frames
  130.     $js_frame_onload=' onload="resizeRowsLeft();"';
  131. }
  132. if ($cfg['QueryFrame']) {
  133. ?>
  134. <script type="text/javascript" language="javascript">
  135. <!--
  136. // added 2004-09-16 by Michael Keck (mkkeck)
  137. //                  bug: #1027321
  138. //                       drop-down databases list keep focus on database change
  139. // modified 2004-11-06: bug #1046434 (Light mode does not work)
  140. var focus_removed = false;
  141. function remove_focus_select() {
  142.     focus_removed = false;
  143.     set_focus_to_nav();
  144. }
  145. function set_focus_to_nav() {
  146.     if (typeof(parent.frames.nav)!='undefined' && focus_removed!=true) {
  147.         parent.frames.nav.focus();
  148.         focus_removed=true;
  149.     } else {
  150.         focus_removed=false;
  151.         setTimeout("set_focus_to_nav();",500);
  152.     }
  153. }
  154. //-->
  155. </script>
  156. <?php
  157. }
  158. ?>
  159. </head>
  160.  
  161. <body id="body_queryFrame" bgcolor="<?php echo $cfg['LeftBgColor']; ?>"<?php echo ((isset($js_frame_onload) && $js_frame_onload!='') ? $js_frame_onload : ''); ?>>
  162. <div id="qfcontainer">
  163. <div align="center">
  164. <?php
  165. if ($cfg['LeftDisplayLogo']) {
  166.     echo '<!-- phpMyAdmin logo -->' . "\n";
  167.     echo '    <a href="http://www.phpmyadmin.net/" target="_blank">';
  168.     if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
  169.         echo '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" alt="phpMyAdmin" border="0" />';
  170.     } else if (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
  171.         echo '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" alt="phpMyAdmin" border="0" />';
  172.     } else {
  173.         echo 'phpMyAdmin';
  174.     }
  175.     echo '</a>' . "\n";
  176.     echo '    <hr id="hr_first" />' . "\n";
  177. } // end of display logo
  178.  
  179. ?>
  180. <!-- Link to the welcome page -->
  181. <?php
  182.     echo '    <a class="item" href="main.php?' . PMA_generate_common_url() . '" target="phpmain' . $hash . '">' . "\n"
  183.        . ($cfg['MainPageIconic']
  184.             ? '        <img src="' . $pmaThemeImage . 'b_home.png" width="16" height="16" border="0" hspace="2" alt="' . $strHome . '" title="' . $strHome . '"'
  185.                     .' onmouseover="this.style.backgroundColor=\'#ffffff\';" onmouseout="this.style.backgroundColor=\'\';" align="middle" />'
  186.             : '        <b>' . $strHome . '</b>') . "\n"
  187.         . '    </a>' . "\n";
  188.     // if we have chosen server
  189.     if ($server != 0) {
  190.         // Logout for advanced authentication
  191.         if ($cfg['Server']['auth_type'] != 'config') {
  192.             echo ($cfg['MainPageIconic'] ? '' : ' - ');
  193.             echo '<a class="item" href="index.php?' . PMA_generate_common_url() . '&old_usr=' . urlencode($PHP_AUTH_USER) . '" target="_parent">' . "\n"
  194.                . ($cfg['MainPageIconic']
  195.                     ? '<img src="' . $pmaThemeImage . 's_loggoff.png" width="16" height="16" border="0" hspace="2" alt="' . $strLogout . '" title="' . $strLogout . '"'
  196.                             .' onmouseover="this.style.backgroundColor=\'#ffffff\';" onmouseout="this.style.backgroundColor=\'\';" align="middle" />'
  197.                     : '<b>' . $strLogout . '</b>')  . "\n"
  198.                . '</a>' . "\n";
  199.         } // end if ($cfg['Server']['auth_type'] != 'config'
  200.  
  201.         if ($cfg['QueryFrame']) {
  202.             $anchor = 'querywindow.php?' . PMA_generate_common_url('', '');
  203.             
  204.             if ($cfg['MainPageIconic']) {
  205.                 $query_frame_link_text = '<img src="' . $pmaThemeImage . 'b_selboard.png" border="0" hspace="1" width="16" height="16" alt="' . $strQueryFrame . '" title="' . $strQueryFrame . '"'
  206.                                        .' onmouseover="this.style.backgroundColor=\'#ffffff\';" onmouseout="this.style.backgroundColor=\'\';" align="middle" />';
  207.             } else {
  208.                 echo '<br />' . "\n";
  209.                 $query_frame_link_text = '<b>' . $strQueryFrame . '</b>';
  210.             }
  211. ?>
  212.     <a href="<?php echo $anchor; ?>&no_js=true" target="phpmain<?php echo $hash; ?>" class="item"
  213.        <?php echo ($cfg['QueryFrameJS'] ? 'onclick="javascript:open_querywindow(\'' . $anchor . '\'); return false;"' : ''); ?>>
  214.         <?php echo $query_frame_link_text; ?>
  215.     </a>
  216. <?php
  217.         } // end if ($cfg['QueryFrame'])
  218.     } // end if ($server != 0)
  219.  
  220. if ($cfg['MainPageIconic']) {
  221.     echo '    <a href="Documentation.html" target="documentation" class="item">' . "\n"
  222.        . '        <img src="' . $pmaThemeImage . 'b_docs.png" border="0" hspace="1" width="16" height="16" alt="' . $strPmaDocumentation . '" title="' . $strPmaDocumentation . '"'
  223.        . ' onmouseover="this.style.backgroundColor=\'#ffffff\';" onmouseout="this.style.backgroundColor=\'\';" align="middle" />' . "\n"
  224.        . '    </a>' . "\n";
  225.     echo '    <a href="' . $cfg['MySQLManualBase'] . '" target="documentation" class="item">' . "\n"
  226.        . '        <img src="' . $pmaThemeImage . 'b_sqlhelp.png" border="0" hspace="1" width="16" height="16" alt="MySQL - ' . $strDocu . '" title="MySQL - ' . $strDocu . '"'
  227.        .' onmouseover="this.style.backgroundColor=\'#ffffff\';" onmouseout="this.style.backgroundColor=\'\';" align="middle" />' . "\n"
  228.        . '    </a>' . "\n";
  229. }
  230. ?>
  231. </div>
  232. <hr id="hr_second" />
  233.  
  234. <?php
  235. if ($cfg['LeftDisplayServers']){
  236.     $show_server_left = TRUE;
  237.     include('./libraries/select_server.lib.php');
  238. } // end if LeftDisplayServers
  239. ?>
  240. <!-- Databases list -->
  241. <?php
  242. /**
  243.  * Get the list and number of available databases.
  244.  * Skipped if no server selected: in this case no database should be displayed
  245.  * before the user choose among available ones at the welcome screen.
  246.  */
  247. if ($server > 0) {
  248.     PMA_availableDatabases(); // this function is defined in "common.lib.php"
  249. } else {
  250.     $num_dbs = 0;
  251. }
  252.  
  253. // Don't display expansible/collapsible database info if:
  254. // 1. $server == 0 (no server selected)
  255. //    This is the case when there are multiple servers and
  256. //    '$cfg['ServerDefault'] = 0' is set. In that case, we want the welcome
  257. //    screen to appear with no database info displayed.
  258. // 2. there is only one database available (ie either only one database exists
  259. //    or $cfg['Servers']['only_db'] is defined and is not an array)
  260. //    In this case, the database should not be collapsible/expandable
  261. if ($num_dbs > 1) {
  262.     // Light mode -> beginning of the select combo for databases
  263.     // Note: When javascript is active, the frameset will be changed from
  264.     // within left.php. With no JS (<noscript>) the whole frameset will
  265.     // be rebuilt with the new target frame.
  266.     if ($cfg['LeftFrameLight']) {
  267.     ?>
  268.     <table border="0" cellpadding="1" cellspacing="0">
  269.         <tr>
  270.             <td align="left" class="heada"><?php echo $strDatabase; ?>:</td>
  271.         </tr>
  272.         <tr>
  273.             <td nowrap="nowrap">
  274.     <form method="post" action="index.php" name="left" target="_parent" style="margin: 0px; padding: 0px;">
  275.     <script type="text/javascript" language="javascript">
  276.     <!--
  277.         document.left.action="left.php";
  278.         document.left.target="nav";
  279.     //-->
  280.     </script>
  281.     <?php
  282.         echo PMA_generate_common_hidden_inputs();
  283.         echo '        <input type="hidden" name="hash" value="' . $hash . '" />' . "\n";
  284.         ?>
  285.         <select name="lightm_db" onchange="remove_focus_select();this.form.submit();">
  286.         <?php
  287.         echo '            <option value="">(' . $strDatabases . ') ...</option>' . "\n";
  288.         $table_list = '';
  289.         $table_list_header = '';
  290.         $db_name    = '';
  291.         $selected_db = 0;
  292.  
  293.         // natural order for db list; but do not sort if user asked
  294.         // for a specific order with the 'only_db' mechanism
  295.  
  296.         // TODO: merge this logic with the one in left.php
  297.  
  298.         if (!is_array($cfg['Server']['only_db']) && $cfg['NaturalOrder'] && $num_dbs > 0) {
  299.             $dblist_temp = $dblist;
  300.             natsort($dblist_temp);
  301.             $i = 0;
  302.             foreach ($dblist_temp as $each) {
  303.                 $dblist[$i] = $each;
  304.                 $i++;
  305.             }
  306.         }
  307.         $parent = '';
  308.         // Gets the tables list per database
  309.         for ($i = 0; $i < $num_dbs; $i++) {
  310.             $db = $dblist[$i];
  311.             $j  = $i + 2;
  312.             if (!empty($db_start) && $db == $db_start) {
  313.                 $selected_db = $j;
  314.             }
  315.             $tables              = PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE);
  316.             $num_tables          = ($tables) ? @PMA_DBI_num_rows($tables) : 0;
  317.             $common_url_query    = PMA_generate_common_url($db);
  318.             if ($num_tables) {
  319.                 $num_tables_disp = $num_tables;
  320.             } else {
  321.                 $num_tables_disp = '-';
  322.             }
  323.             // Get additional information about tables for tooltip
  324.             if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303
  325.                 && $num_tables
  326.                 && (!$cfg['LeftFrameLight'] || $selected_db == $j)) {
  327.                 $tooltip = array();
  328.                 $tooltip_name = array();
  329.                 $result  = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db));
  330.                 while ($tmp = PMA_DBI_fetch_assoc($result)) {
  331.                     $tooltip_name[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '');
  332.                     $tmp['Comment'] = ($cfg['ShowTooltipAliasTB'] && $cfg['ShowTooltipAliasTB'] !== 'nested' ? $tmp['Name'] : $tmp['Comment']);
  333.                     $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '')
  334.                                            . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')';
  335.                 } // end while
  336.             } // end if
  337.  
  338.             // garvin: Get comments from PMA comments table
  339.             $db_tooltip = '';
  340.             if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) {
  341.                 $tmp_db_tooltip = PMA_getComments($db);
  342.                 if (is_array($tmp_db_tooltip)) {
  343.                     $db_tooltip = implode(' ', $tmp_db_tooltip);
  344.                 }
  345.             }
  346.  
  347.             // Builds the databases' names list
  348.             if (!empty($db_start) && $db == $db_start) {
  349.                 $table_title = array();
  350.                 $table_array = array();
  351.                 // Gets the list of tables from the current database
  352.                 while (list($table) = PMA_DBI_fetch_row($tables)) {
  353.                     $table_array[$table] = '';
  354.                     $url_title  = (!empty($tooltip) && isset($tooltip[$table]))
  355.                                 ? htmlspecialchars($tooltip[$table])
  356.                                 : '';
  357.                     $alias = (!empty($tooltip_name) && isset($tooltip_name[$table]))
  358.                                 ? htmlspecialchars($tooltip_name[$table])
  359.                                 : '';
  360.                     $book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', 'label');
  361.                 } // end while (tables list)
  362.                 $selected = ' selected="selected"';
  363.             } else {
  364.                 $selected = '';
  365.             } // end if... else...
  366.  
  367.             $db_disp = $db;
  368.             if ($cfg['LeftFrameDBTree']) {
  369.                 if ($i == 0) {
  370.                     $parts = explode($cfg['LeftFrameDBSeparator'],$db,2);
  371.                 } else {
  372.                     $parts = $next_parts;
  373.                 }
  374.                 if ($i == $num_dbs - 1) {
  375.                     $next_parts = array();
  376.                 } else {
  377.                     $next_parts = explode($cfg['LeftFrameDBSeparator'],$dblist[$i+1],2);
  378.                 }
  379.                 if (count($next_parts) > 1 && $parts[0] == $next_parts[0] && $parent != $parts[0]) {
  380.                     echo '      '
  381.                         . '<optgroup label="'.htmlspecialchars($parts[0]).'">'."\n";
  382.                     $parent = $parts[0];
  383.                 }
  384.                 if (count($parts) > 1 && $parent == $parts[0]) {
  385.                     $db_disp = $cfg['LeftFrameDBSeparator'] . $parts[1];
  386.                 }
  387.             }
  388.             
  389.             if (!empty($num_tables)) {
  390.                 echo '            '
  391.                    . '<option value="' . htmlspecialchars($db) . '"' . $selected . '>'
  392.                    . ($db_tooltip != '' && $cfg['ShowTooltipAliasDB'] ? htmlspecialchars($db_tooltip) : htmlspecialchars($db_disp)) . ' (' . $num_tables . ')</option>' . "\n";
  393.             } else {
  394.                 echo '            '
  395.                    . '<option value="' . htmlspecialchars($db) . '"' . $selected . '>'
  396.                    . ($db_tooltip != '' && $cfg['ShowTooltipAliasDB'] ? htmlspecialchars($db_tooltip) : htmlspecialchars($db_disp)) . ' (-)</option>' . "\n";
  397.             } // end if... else...
  398.  
  399.             if ($cfg['LeftFrameDBTree']) {
  400.                 if (!empty($parent) && (count($next_parts) == 0 || $parent != $next_parts[0])) {
  401.                     echo '      '
  402.                         . '</optgroup>'."\n";
  403.                     $parent = '';
  404.                 }
  405.             }
  406.         } // end for $i (db list)
  407.         ?>
  408.         </select>
  409.         <noscript>
  410.             <input type="submit" name="Go" value="<?php echo $strGo; ?>" />
  411.         </noscript>
  412.         </form>
  413.             </td>
  414.         </tr>
  415.     </table>
  416.     <hr id="hr_third" />
  417.     <?php
  418.     } // end if LeftFrameLight
  419. } // end if num_db > 1
  420.     ?>
  421.     <form name="queryframeform" action="queryframe.php" method="get" style="margin:0px; padding:0px; display:none;">
  422.         <input type="hidden" name="db" value="" />
  423.         <input type="hidden" name="table" value="" />
  424.         <input type="hidden" name="framename" value="queryframe" />
  425.     </form>
  426.     <form name="hashform" action="queryframe.php" style="margin:0px; padding:0px; display:none;">
  427.         <input type="hidden" name="hash" value="<?php echo $hash; ?>" />
  428.     </form>
  429.     </div>
  430. </body>
  431. </html>
  432.  
  433. <?php
  434. /**
  435.  * Close MySql connections
  436.  */
  437. if (isset($dbh) && $dbh) {
  438.     @PMA_DBI_close($dbh);
  439. }
  440. if (isset($userlink) && $userlink) {
  441.     @PMA_DBI_close($userlink);
  442. }
  443.  
  444.  
  445. /**
  446.  * Sends bufferized data
  447.  */
  448. if (isset($cfg['OBGzip']) && $cfg['OBGzip']
  449.     && isset($ob_mode) && $ob_mode) {
  450.      PMA_outBufferPost($ob_mode);
  451. }
  452. ?>
  453.